package com.project.advertisement.dao;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;

public class AdvertisementDao extends SQLiteOpenHelper {
	private String createEmailTable = "create table if not exists email ( id integer primary key autoincrement,emailAddress text not null)";
	private String createEmailContentTable = "create table if not exists emailContent ( id integer primary key autoincrement,emailContent text not null)";

	public AdvertisementDao(Context context, String name,
			CursorFactory factory, int version) {
		super(context, name, factory, version);

	}

	@Override
	public void onCreate(SQLiteDatabase database) {
		database.execSQL(createEmailContentTable);
		database.execSQL(createEmailTable);
	}

	@Override
	public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {
		// TODO Auto-generated method stub

	}

	public long registerEmail(String emailId) {

		SQLiteDatabase database = getWritableDatabase();
		ContentValues values = new ContentValues();
		values.put("emailAddress", emailId);

		long rowId = database.insert("email", null, values);
		database.close();
		return rowId;

	}
	public long registerEmailContent(String emailContent) {

		SQLiteDatabase database = getWritableDatabase();
		ContentValues values = new ContentValues();
		values.put("emailContent", emailContent);

		long rowId = database.insert("emailContent", null, values);
		database.close();
		return rowId;

	}
	public boolean isEmailRegistered(String emailId) {
		SQLiteDatabase database=getReadableDatabase();
		boolean value=false;
		String []param=new String[1];
		param[0]=emailId;
		Cursor cursor=database.rawQuery("select * from email where emailAddress=?", param);
		if(cursor.moveToFirst())
			value=true;
		cursor.close();
	    database.close();
	    return value;
	}
	
	/*public long updateEmailContent(String emailContent) {

		SQLiteDatabase database = getWritableDatabase();
		ContentValues values = new ContentValues();
		values.put("emailContent", emailContent);

		long rowId = database.update("emailContent", values, whereClause, whereArgs);//database.insert("emailContent", null, values);
		database.close();
		return rowId;

	}*/


}
